﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EntitiesGenerator.Utils
{
    public static class TypeMapper
    {
        public static string ToCSharpTypeString(this Type type, bool nullable)
        {

            if (type == typeof(byte) && !nullable)
                return "byte";
            else if (type == typeof(short) && !nullable)
                return "short";
            else if (type == typeof(int) && !nullable)
                return "int";
            else if (type == typeof(long) && !nullable)
                return "long";
            else if (type == typeof(sbyte) && !nullable)
                return "sbyte";
            else if (type == typeof(ushort) && !nullable)
                return "ushort";
            else if (type == typeof(ushort) && !nullable)
                return "ushort";
            else if (type == typeof(ushort) && !nullable)
                return "ushort";

            else if (type == typeof(byte) && nullable)
                return "byte?";
            else if (type == typeof(sbyte) && nullable)
                return "sbyte?";
            else if (type == typeof(short) && nullable)
                return "short?";
            else if (type == typeof(int) && nullable)
                return "int?";
            else if (type == typeof(long) && nullable)
                return "long?";
            else if (type == typeof(ushort) && nullable)
                return "ushort?";
            else if (type == typeof(ushort) && nullable)
                return "ushort?";
            else if (type == typeof(ushort) && nullable)
                return "ushort?";

            else if (type == typeof(float) && !nullable)
                return "float";
            else if (type == typeof(double) && !nullable)
                return "double";
            else if (type == typeof(decimal) && !nullable)
                return "decimal";

            else if (type == typeof(float) && nullable)
                return "float?";
            else if (type == typeof(double) && nullable)
                return "double?";
            else if (type == typeof(decimal) && nullable)
                return "decimal?";

            else if (type == typeof(Guid) && nullable)
                return "Guid?";
            else if (type == typeof(Guid) && !nullable)
                return "Guid";

            else if (type == typeof(DateTime) && nullable)
                return "DateTime?";
            else if (type == typeof(DateTime) && !nullable)
                return "DateTime";

            else if (type == typeof(string))
                return "string";

            else if (type == typeof(bool) && nullable)
                return "bool?";
            else if (type == typeof(bool) && !nullable)
                return "bool";

            else if (type == typeof(byte[]))
                return "byte[]";

            else
                throw new Exception($"TypeMapper:[{type.FullName}]类型无法转换!");
        }
    }
}
